package com.aceitunaproject.mapdisplay.component;

import javax.swing.JPanel;

import com.aceitunaproject.mapdisplay.MapDrawer;
import com.aceitunaproject.mapdisplay.MapDrawerImpl;
import com.aceitunaproject.mapdisplay.model.map.Map;
import com.aceitunaproject.mapdisplay.model.map.tile.Tile;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
 * 
 * @author Federico Bergstein
 * 
 *         A simple class to display the map
 */
public class MapPane extends JPanel {

	private static final long serialVersionUID = 1L;

	protected MapDrawer mapDrawer;

	public MapPane(Tile[][] tiles) {
		mapDrawer = new MapDrawerImpl(this, new Map(tiles), new Dimension(100,
				100));
		mapDrawer.setFocus(0, 0);
		mapDrawer.setDisplayGrid(false);
	}

	public void setMapModel(Tile[][] tiles) {
		mapDrawer = new MapDrawerImpl(this, new Map(tiles), new Dimension(100,
				100));
		this.repaint();
	}

	/**
	 * Sets the map drawer object to use to display the map
	 * 
	 * @param mapDrawer
	 *            the map drawer object to use to display the map
	 */
	public void setMapDrawer(MapDrawer mapDrawer) {
		this.mapDrawer = mapDrawer;
	}

	@Override
	public void paintComponent(Graphics g) {

		Graphics2D g2d = (Graphics2D) g;
		if (mapDrawer != null) {

			mapDrawer.display(g2d);

		}
		

	}
}
